using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Web.Core.Objects;
using Web.Core;

public partial class AdminCP_AdminControls_AddEditCurrencies : System.Web.UI.UserControl
{
    int curID = 0;
    public string header = "";
    string cDo = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        cDo = Request.Params["do"];
        if (cDo != null)
        {
            InitControl();
        }
    }
    void InitControl()
    {
        RequiredFieldValidatorName.ErrorMessage = Resources.Lang.Require;
        RequiredFieldValidatorSymbol.ErrorMessage = Resources.Lang.Require;
        RequiredFieldValidatorRate.ErrorMessage = Resources.Lang.Require;

        if (Request.Params["cid"] != null)
        {            
            curID = int.Parse(Request.Params["cid"]);
        }
        switch (cDo)
        {
            case "edit":
                header = Resources.Lang.Edit;
                Currency curr = Currencies.GetCurrenciesByID(curID);
                this.txtName.Text = curr.Name;
                this.txtSymbol.Text = curr.Symbol;
                this.txtRate.Text = curr.Rate.ToString();
                break;
            case "add":
                header = Resources.Lang.Add;                
                break;
            default:
                break;
        }
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {        
        if (cDo == "edit")
        {
            Currency curr = new Currency(curID, txtName.Text, txtSymbol.Text, float.Parse(txtRate.Text));
            Currencies.Update(curr);
        }
        else if (cDo == "add")
        {
            Currency curr = new Currency(0, txtName.Text, txtSymbol.Text, float.Parse(txtRate.Text));
            Currencies.Insert(curr);
        }
        Response.Redirect("Currencies.aspx");
    }
}
